﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DataAccess;
namespace SQT.tracnghiem
{
    public partial class Lesson : System.Web.UI.Page
    {
        public int level = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["level"] != null)
            {
                level = int.Parse(Session["level"].ToString());
            }
        }
        public static string convertToUnSign(string s)
        {
            string convert = "ĂÂÀẰẦÁẮẤẢẲẨÃẴẪẠẶẬỄẼỂẺÉÊÈỀẾẸỆÔÒỒƠỜÓỐỚỎỔỞÕỖỠỌỘỢƯÚÙỨỪỦỬŨỮỤỰÌÍỈĨỊỲÝỶỸỴĐăâàằầáắấảẳẩãẵẫạặậễẽểẻéêèềếẹệôòồơờóốớỏổởõỗỡọộợưúùứừủửũữụựìíỉĩịỳýỷỹỵđ\".:;'<>?~!@#$%^&*()_+-=\\/*,";
            string To = "aaaaaaaaaaaaaaaaaeeeeeeeeeeeooooooooooooooooouuuuuuuuuuuiiiiiyyyyydaaaaaaaaaaaaaaaaaeeeeeeeeeeeooooooooooooooooouuuuuuuuuuuiiiiiyyyyyd                           ";
            for (int i = 0; i < To.Length; i++)
            {
                s = s.Replace(convert[i], To[i]);
            }
            return s;
        }
        public int? findReplyTeacher(int cmt)
        {
            int? id = null;
            var get_reply = new TblLessonCommentReplyController().FetchAll().Where(x => x.CmtId == cmt);
            foreach (TblLessonCommentReply reply in get_reply)
            {
                var get_teacher_reply = new TblUserController().FetchAll().Where(x => x.UserId == reply.UserId).Single();
                if (get_teacher_reply.UserLevel == 5)
                    id = reply.Id;
            }
            return id;
        }
        public string datetimeToString(string d)
        {
            string s = "";

            DateTime date = DateTime.Parse(d);
            if (DateTime.Now.Date == date.Date)
            {
                s = "Hôm nay lúc " + configTime(date.Hour) + ":" + configTime(date.Minute);
            }
            else
            {
                if (date.Year == DateTime.Now.Year && date.Month == DateTime.Now.Month && DateTime.Now.Day - date.Day == 1)
                {
                    s = "Hôm qua lúc " + configTime(date.Hour) + ":" + configTime(date.Minute);
                }
                else
                {
                    if (DateTime.Now.Year == date.Year)
                    {
                        s = date.Day + " tháng " + date.Month + " lúc " + configTime(date.Hour) + ":" + configTime(date.Minute);
                    }
                    else
                        s = date.Day + " tháng " + date.Month + " " + date.Year + " lúc " + configTime(date.Hour) + ":" + configTime(date.Minute);
                }
            }
            return s;
        }
        private string configTime(int t)
        {
            string repair = "";
            if (t < 10)
                repair = "0" + t;
            else
                repair = t.ToString();
            return repair;
        }
        public bool checkRoleUser(string s)
        {
            if (s == "")
                return false;
            else
            {
                int role_length = s.Split(',').Length;
                string[] split = new string[role_length];
                split = s.Split(',');

                for (int i = 0; i < role_length; i++)
                {
                    if (int.Parse(split[i]) == level)
                        return true;
                }
            }
            return false;
        }

        public static string convertToUrl(string s)
        {
            string url = "";
            s = s.ToLower();
            if (s.IndexOf(' ') != -1)
            {
                string[] split = new string[s.Split(' ').Length];
                split = s.Split(' ');

                for (int i = 0; i < split.Length; i++)
                {
                    url += convertToUnSign(split[i].Trim());
                    if (i < split.Length - 1)
                        url += "-";
                }
                s = url;
            }
            else
            {
                url += convertToUnSign(s);
            }
            s = url;
            return s;
        }
    }
}